package org.apache.solr.util;

import java.io.File;
import java.io.FileFilter;
import java.util.regex.*;

/**
 * Accepts any file whose name matches the pattern
 */
public final class RegexFileFilter implements FileFilter {

    final Pattern pattern;

    public RegexFileFilter(String regex) {
        this(Pattern.compile(regex));
    }

    public RegexFileFilter(Pattern regex) {
        pattern = regex;
    }

    @Override
    public boolean accept(File f) {
        return pattern.matcher(f.getName()).matches();
    }

    @Override
    public String toString() {
        return "regex:" + pattern.toString();
    }
}
